<?php
class FormProcessor_UserDetail extends FormProcessor {
	//TODO 用户详细信息处理
	protected $db = null;
	protected $user = null;
	
	public function __construct($db, $userid) {
		$this->db = $db;
		$this->user = new DatabaseObject_User($this->db);
		$this->user->load($userid);
		$this->user->type = 'member';
	}
	
	public function process(Zend_Controller_Request_Abstract $request) {
		//邮箱
        $this->email = $this->sanitize($request->getPost('email'));
        $validator = new Zend_validate_EmailAddress();
        
        if (strlen($this->email) == 0) {
            $this->addError('email', '请输入邮箱，以便我们与你联系');
        } elseif (!$validator->isValid($this->email)) {
            $this->addError('email', '邮箱不合法');
        } else {
            $this->user->email = $this->email;
        }
        
        //昵称
        $this->nickname = $this->sanitize($request->getPost('nickname'));
        if (!strlen($this->nickname) == 0) {
        	$this->user->profile->nick = $this->nickname;
        }
        
        //性别
        $gender = $request->getPost('gender');
        if ($gender == 1 or $gender == 2) {
        	if ($gender == 1) {
        		$this->user->profile->gender = '男';
        	} else {
        		$this->user->profile->gender = '女';
        	}
        	$this->gender = $gender;
        }
        
        //TODO 验证生日
        
        //msn
        $this->msn = $this->sanitize($request->getPost('msn'));
        if (!strlen($this->msn) == 0) {
        	$this->user->profile->msn = $this->msn;
        }
        
        //qq
        $this->qq = $this->sanitize($request->getPost('qq'));
        if (!strlen($this->qq) == 0) {
        	$this->user->profile->qq = $this->qq;
        }
        
        //site
        $this->site = $this->sanitize($request->getPost('site'));
        if (!strlen($this->site) == 0) {
        	$this->user->profile->site = $this->site;
        }
        
        //stauts
        $this->status = $this->sanitize($request->getPost('status'));
        if (!strlen($this->status) == 0) {
        	$this->profile->status = $this->status;
        }
        
        //TODO 出生地 居住地
        
        //alipy
        $this->alipy = $this->sanitize($request->getPost('alipy'));
        if (!strlen($this->alipy) == 0) {
        	$this->profile->alipy = $this->alipy;
        }
        
        //TODO 血型
        
        if (!$this->hasError()) {
        	$this->user->save();
        }
        
        return !$this->hasError();
	}
}
?>